package com.dubbo.framework.protocol;

import cn.hutool.core.util.StrUtil;
import cn.hutool.system.SystemUtil;
import com.dubbo.framework.protocol.dubbo.DubboProtocol;
import com.dubbo.framework.protocol.http.HttpProtocol;
import lombok.extern.slf4j.Slf4j;

import static com.dubbo.framework.protocol.ProtocolConsts.*;

/**
 * 协议工厂
 * <p>
 * 默认使用 http协议
 *
 * @author by Mr. Li 2021/4/30 14:25
 */
@Slf4j
public class ProtocolFactory {

    public static Protocol getProtocol() {
        // 通过系统参数动态切换协议
        String protocolName = SystemUtil.get("protocolName");

        if (StrUtil.isBlank(protocolName)) protocolName = HTTP_NAME;

        switch (protocolName) {
            case HTTP_NAME:
                return new HttpProtocol();
            case DUBBO_NAME:
                return new DubboProtocol();
            default:
                break;
        }
        return new HttpProtocol();
    }
}
